//package com.community.zhihuishequ.third.aliPush;
//
//import android.content.Context;
//
//import com.alibaba.sdk.android.push.CloudPushService;
//import com.alibaba.sdk.android.push.CommonCallback;
//import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
//import com.alibaba.sdk.android.push.register.HuaWeiRegister;
//import com.alibaba.sdk.android.push.register.MiPushRegister;
//import com.blankj.utilcode.util.LogUtils;
//import com.blankj.utilcode.util.ToastUtils;
//import com.camp.R;
//import com.camp.UserInfo;
//import com.camp.net.AppInterceptor;
//import com.camp.net.AppRestService;
//import com.camp.net.entity.AppResponse;
//import com.camp.utils.NetworkUtil;
//import com.camp.utils.TinyDB;
//
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.functions.Consumer;
//import io.reactivex.schedulers.Schedulers;
//
///**
// * Created by Rick on 17/12/12.
// * 阿里推送的类
// */
//
//public class AliPush {
//
//    private static final String TAG = "AliPush";
//
//    /**
//     * 初始化云推送通道
//     */
//    public static void initCloudChannel(final Context applicationContext) {
//        PushServiceFactory.init(applicationContext);
//        CloudPushService pushService = PushServiceFactory.getCloudPushService();
//        pushService.register(applicationContext, new CommonCallback() {
//            @Override
//            public void onSuccess(String response) {
//                String deviceId = PushServiceFactory.getCloudPushService().getDeviceId();
//                TinyDB tinyDB = new TinyDB(applicationContext);
//                tinyDB.putString("aliPushDeviceId", deviceId);
//                UserInfo.getInstance().setAliPushDeviceId(deviceId);
//                LogUtils.i(TAG, "注册阿里推送成功, 设备Id:" + deviceId);
//
//                regAliDeviceIdToServer(applicationContext);
//
//            }
//
//            @Override
//            public void onFailed(String errorCode, String errorMessage) {
//                LogUtils.i(TAG, "注册阿里推送失败", "失败代码:" + errorCode, "失败信息:" + errorMessage);
//            }
//        });
//        // 注册方法会自动判断是否支持小米系统推送，如不支持会跳过注册。
//        MiPushRegister.register(applicationContext, "2882303761517719597", "5151771925597");
//        // 注册方法会自动判断是否支持华为系统推送，如不支持会跳过注册。
//        HuaWeiRegister.register(applicationContext);
//        //GCM/FCM辅助通道注册
////        GcmRegister.register(this, sendId, applicationId); //sendId/applicationId为步骤获得的参数
//    }
//
//    public static void regAliDeviceIdToServer(final Context context) {
//        String aliDeviceId = UserInfo.getInstance().getAliPushDeviceId();
//        String username = UserInfo.getInstance().getUserName();
//        if (aliDeviceId == null || username == null) {
//            return;
//        }
//        // 直接发送给我们的服务器
//        NetworkUtil.baseRetrofit(AppRestService.BASE_URL, new AppInterceptor(context))
//                .create(AppRestService.class)
//                .doRegAliDeviceId(aliDeviceId)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Consumer<AppResponse>() {
//                    @Override
//                    public void accept(AppResponse appResponse) throws Exception {
//
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        ToastUtils.showShort(R.string.error_network);
//                    }
//                });
//    }
//}
